package com.appkubes.mall.restful.application.cart.dao;

import com.appkubes.mall.core.dao.BaseMallCartDao;
import com.appkubes.mall.restful.application.cart.entity.model.CartListModel;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CartDao extends BaseMallCartDao {

    @Select({
            "select sum(ifnull(t1.num,0)) as total from mall_cart t1 " +
                    " left join mall_goods t3 on t3.goods_key = t1.goods_key and t3.state=1 and t3.end_time>unix_timestamp(current_timestamp()) " +
                    " where t1.user_key=#{userKey} "
    })
    Integer getCartNums(@Param("userKey") String userKey);


    @Select({
            "select t1.*,t3.pic as pic,t3.pics,t3.use_attr as useAttr,t1.activity_key as activityKey, t3.price as price, " +
                    "t3.name, t3.cat_key, t3.state, " +
                    "t3.subheading" +
                    " from mall_cart t1 " +
                    " left join mall_goods t3 on t3.goods_key = t1.goods_key and t3.state = 1" +
                    " where t1.user_key=#{userKey} " +
                    " order by t1.update_time desc"
    })
    List<CartListModel> getCarts(@Param("userKey") String userKey);

}
